Function length(r As String) As Long
	k = InStr(r, "*")
	length = Right(r, (Len(r) - k))
	length = Val(length)    '根据规格单元格求出裁切线长。
End Function

Function width(r As String) As Long
	k = InStr(r, "*")
	width = Left(r, (k - 1))
	width = Val(width)      '根据规格单元格求出裁切幅宽。
End Function

Function speed(l)
	Select Case l
	Case 400 To 600
	speed = (0.3 * l - 65) * 0.7
	Case 600 To 800
	speed = (0.55 * l - 200) * 0.9
	Case 800 To 889
	speed = 1.236 * l - 748.8
	Case 889 To 1250
	speed = 350
	Case 1250 To 1300
	speed = -0.4 * l + 850
	Case 1300 To 1440
	speed = -0.214 * l + 608.16
	Case 1440 To 1600
	speed = -0.0875 * l + 426
	End Select
End Function

'pm4 main--------------------
Function CALCUPM4(pm As String, g As Long, a As Long, s As String, m, nwm As String) As Double
If m = 0 Then CALCUPM4 = 0
If m > 0 Then
b = length(s)            '根据规格单元格求出裁切线长。
wid = width(s)
a1 = wid * (Int(a / wid))
k1 = speed(b) / 350      'k1为车速系数以350m/min为1。
Select Case g
Case Is <= 300
 k2 = 1                        'k2为单双切系数。
Case Is > 300
 k2 = 0.67
End Select
If (pm = "IV2") Then k2 = 0.7       '修正IV2  单切
If (pm = "GAB") And (g <= 350) Then k2 = 1           '修正gab 350 双切
If (Left(pm, 2) = "PC") And (nwm = "内贸") Then k2 = 0.67  '修正pc neimao danqie
If (Left(pm, 2) = "PC") And (nwm = "外贸") Then k2 = 1 ' 修正pc waimao shuangqie
If m <= 4 Then k2 = 0.67     '修正单卷单切
K3 = 1
If (pm = "GAB") Or (Left(pm, 2) = "PC") Then K3 = (100 / 110 + 115 / 125 + 115 / 125) / 3 '修正白卡系数
K4 = 1
If pm = "GAB" Then K4 = 1 / 1.1              'GABzhengjia10%
'克重系数k
k = 1
If g = 190 Then k = 0.8

CALCUPM4 = m * 2361 / a1 * 300 / g / k1 / k2 * K3 * K4 * k '求出折合量
End If
Select Case b
Case Is <= 600
CALCUPM4 = CALCUPM4 * 0.6
Case Is <= 650
CALCUPM4 = CALCUPM4 * 0.65
Case Is <= 750
CALCUPM4 = CALCUPM4 * 0.7
End Select
If CALCUPM4 = 0 Then CALCUPM4 = ""
If wid < 400 Then CALCUPM4 = Flase

End Function
Function calcu(pm As String, g As Long, a As Long, s As String, m, nwm As String) As Double
If m = 0 Then calcu = 0
If m > 0 Then
b = length(s)            '根据规格单元格求出裁切线长。
wid = width(s)
a1 = wid * (Int(a / wid))
k1 = speed(b) / 300       'k1为车速系数以300m/min为1。
Select Case g
Case Is <= 300
 k2 = 1                        'k2为单双切系数。
Case Is > 300
 k2 = 0.67
End Select
If (pm = "IV2") Then k2 = 0.7       '修正IV2  单切
If (pm = "GAB") And (g <= 350) Then k2 = 1           '修正gab 350 双切
If (Left(pm, 2) = "PC") And (nwm = "内贸") Then k2 = 0.67  '修正pc neimao danqie
If (Left(pm, 2) = "PC") And (nwm = "外贸") Then k2 = 1 ' 修正pc waimao shuangqie
If m <= 4 Then k2 = 0.67     '修正单卷单切
K3 = 1
If (pm = "GAB") Or (Left(pm, 2) = "PC") Then K3 = (100 / 110 + 115 / 125 + 115 / 125) / 3 '修正白卡系数
K4 = 1
If pm = "GAB" Then K4 = 1 / 1.1              'GABzhengjia10%
If (pm = "SBS") Or (pm = "SB0") Then K4 = 1 / 0.67
If (pm = "GAB") And (g = 350) Then K4 = 1 * 1.1

calcu = m * 2361 / a1 * 300 / g / k1 / k2 * K3 * K4 '求出折合量
End If
'短规格修正


End Function


'PM6calcu2
Function calcu2(pm As String, g As Long, a As Long, s As String, m, nwm As String) As Double
If pm = "UAB" Then pm = "GAB"

If m = 0 Then calcu2 = 0
If m > 0 Then
b = length(s)            '根据规格单元格求出裁切线长。
wid = width(s)
a1 = wid * (Int(a / wid))
Select Case b            'k1为车速系数。
Case Is >= 1361
k1 = 0.7
Case Is >= 1271
k1 = 0.8
Case Is >= 1171
k1 = 0.9
Case Is >= 830
k1 = 1
Case Is >= 790
k1 = 0.95
Case Is >= 760
k1 = 0.85
Case Is >= 725
k1 = 0.8
Case Is >= 670
k1 = 0.75
Case Is >= 620
k1 = 0.65
Case Is >= 570
k1 = 0.55
Case Is >= 500
k1 = 0.4
Case Is >= 480
k1 = 0.39

End Select
Select Case g
Case Is <= 300
 k2 = 1                        'k2为单双切系数。
Case Is > 300
 k2 = 0.67
End Select
'If (pm = "GAB") And (g <= 350) Then k2 = 1           '修正gab 350 双切  gab 350 单切
If (Left(pm, 2) = "PC") And (nwm = "内贸") Then k2 = 0.67  '修正pc neimao danqie
If (Left(pm, 2) = "PC") And (nwm = "外贸") Then k2 = 1 ' 修正pc waimao shuangqie
If m <= 4 Then k2 = 0.67     '修正单卷单切
K3 = 1
If (pm = "GAB") Or (Left(pm, 2) = "PC") Then K3 = (100 / 110 + 115 / 125 + 115 / 125) / 3 '修正白卡系数
K4 = 1
If pm = "GAB" Or pm = "UAB" Then K4 = 1 / 1.1            'GAB/uab zhengjia10%
If (pm = "SBS") Or (pm = "SB0") Then K4 = 1 / 0.67




calcu2 = m * 2361 / a1 * 300 / g / k1 / k2 * K3 * K4 '求出折合量

End If

End Function



